module(..., package.seeall)
--- 模块功能：其他方式开锁
-- @author zhangfenghe
-- @module access_control_system.otherUnlockMethods
-- @license MIT
-- @copyright openLuat
-- @release 2024.02.27
require "mqtt"
require "misc"
require "nvm"
require "config"
require "mqttHostOutMsg"
require "utilsACS"
-- 初始化配置文件
nvm.init("config.lua", true)
-- 获取配置文件信息
local slaveNo, hostNo, openTime = nvm.get("ClientNo"), nvm.get("HostNo"),
                                  nvm.get("OpenTime")
local topic, sendMsg = "", ""
local function otherWayOpen()
    -- 开门
    utilsACS.OpenDoorAction()
    sys.wait(1000 * openTime)
    -- 关门
    utilsACS.ClosDoorAction()
end
local function gpio25IntFnc(msg)
    log.info("testGpioSingle.gpio25IntFnc", msg, GetGpio25Fnc())
    if msg == cpu.INT_GPIO_NEGEDGE then
        log.info(
            ">>>>>>>>>>>下降沿其他方式开锁，其他方式开锁逻辑开始！！<<<<<<<<<<<<<<<<<")
        -- 其他方式开门
        sys.taskInit(otherWayOpen)
        -- 向主机发送其他方式开门
        topic = "acs/" .. hostNo
        sendMsg = "{\"action\":\"other\",\"slaveNo\":\"" .. slaveNo ..
                      "\"}"
        mqttHostOutMsg.InsertHostMsg(topic, sendMsg, 0)
    end
end

-- 下降沿中断时：msg为cpu.INT_GPIO_POSEDGE；下降沿中断时：msg为cpu.INT_GPIO_NEGEDGE
GetGpio25Fnc = pins.setup(pio.P0_25, gpio25IntFnc)
